home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tb3to5.zip / TB3TO5.PAS < prev   
Pascal/Delphi Source File  |  1993-01-04  |  5KB  |  174 lines

  1. program TB3TO5;
  2.  
  3. {Program to convert Turbo 3 toolbox data files to Turbo 4/5 data files.
  4.  This is accomplished by changing the status word (beginning of each
  5.  record) from a two Byte integer to a four Byte longint.  Only active
  6.  records are copied.  Deleted records are compressed out of the output
  7.  file.  This program will only copy data records.  It will be necessary
  8.  to reconstruct the index of the file with a program written in, or con-
  9.  verted to Turbo 4/5.
  10.  
  11.  Three parameters must be supplied to the program:
  12.  
  13.    The first parameter is the path and name of the Turbo 3 input file.
  14.  
  15.    The Second is the path and name of the new Turbo 4/5 output file.
  16.  
  17.    The Third parameter is the record length of the Turbo 3 data records.
  18.  
  19.  Restrictions: data records must be less than 4000 Bytes in length!
  20.                This may be changed by modifying the array size of InBuffer.
  21.  
  22.    }
  23.  
  24. uses crt;
  25.  
  26. type HeaderRec = record    { Turbo 4/5 header record }
  27.        FirstFree: longint;
  28.        NumberFree: longint;
  29.        Int1: longint;
  30.        RecLen: word
  31.        end;
  32.  
  33. var InBuffer: array [1..4002] of Byte;  {Input Buffer}
  34.     ErrorCode: integer;
  35.     InFile,OutFile : file;
  36.     Header: HeaderRec;
  37.     RecNum: longint;
  38.     RecSize: word;
  39.     OutCount : longint;
  40.     lastj : integer;
  41.  
  42. {PercentLine provides a horizontal bar graph on the screen.  The first
  43. parameter is the vertical position and is specified in the range 0 to 23.
  44. The percentage is calculated from the second and third parameters; in which
  45. the second (dividend) is divided by the third (divisor) to calculate the
  46. percentage.}
  47.  
  48. procedure PercentLine(y,dvd,dvr:longint);
  49. var
  50.    work : string[20];
  51.    i,j : integer;
  52.    per,rdvd,rdvr,jr : real;
  53.    SaveAttr : Byte;
  54.  
  55. begin
  56.    SaveAttr:=TextAttr;
  57.    if y > 23 then y:=23;
  58.    if y < 0 then y:=0;
  59.    if (dvd = 0) and (dvr = 0) then
  60.    begin
  61.       GotoXY(1,Y+1);
  62.       TextAttr:=$70;
  63.       Write(' 0.....10.....20.....30.....40.....50.....60.....70.....80.....90....100% ');
  64.       GotoXY(1,Y+2);
  65.       Write('                                                                          ');
  66.       lastj:=0;
  67.       TextAttr:=SaveAttr;
  68.    end else
  69.    begin
  70.       if dvr = 0 then exit;
  71.       Rdvd:=dvd * 1.0;
  72.       Rdvr:=dvr * 1.0;
  73.       per:=Rdvd / Rdvr;
  74.       if per <= 1.0 then
  75.       begin
  76.          jr:=70.0 * per;
  77.          j:=round(jr);
  78.          TextAttr:=$07;
  79.          str((per*100.0):3:0,work);
  80.          GotoXY(76,Y+2);
  81.          Write(work,'%');
  82.          if j >= lastj then
  83.          begin
  84.             for i:=lastj to j+1 do
  85.             begin
  86.                if i > 0 then
  87.                begin
  88.                   GotoXY(I+1,Y+2);
  89.                   Write('▄');
  90.                end;
  91.             end;
  92.          end;
  93.          lastj:=j+1;
  94.       end;
  95.    end;
  96.    TextAttr:=SaveAttr;
  97. end;
  98.  
  99. { Start of main line program }
  100.  
  101. begin
  102.    clrscr;
  103.     case paramcount of
  104.     0: begin
  105.           Writeln('Usage: TB3TO5 from_filename to_filename recsize');
  106.           halt;
  107.        end;
  108.     1,2 : begin
  109.              Writeln('Not enough parameters.');
  110.              halt;
  111.           end;
  112.     3: begin end;
  113.     else begin
  114.             Writeln('Too many parameters.');
  115.             halt;
  116.          end;
  117.     end;
  118.     val(paramstr(3),RecSize,ErrorCode);
  119.      if (ErrorCode<>0) or (RecSize<14) then
  120.     begin
  121.        Writeln('Record size out of range.'^G);
  122.        halt;
  123.     end;
  124.     assign(InFile,paramstr(1));
  125.     {$I-}
  126.     reset(InFile,RecSize);            { Open the input data file }
  127.     {$I+}
  128.     if ioresult <> 0 then
  129.     begin
  130.        Writeln('Could not open input file ''',paramstr(1),'''',^G);
  131.        halt;
  132.     end;
  133.     assign(OutFile,paramstr(2));
  134.     {$I-}
  135.     reWrite(OutFile,RecSize+2);       { Open the output data file }
  136.     {$I+}
  137.     if ioresult <> 0 then
  138.     begin
  139.        Writeln('Could not create output file ''',paramstr(1),'''',^G);
  140.        halt;
  141.     end;
  142.     Writeln('Original record size of ',paramstr(1),' is ',recsize,'.');
  143.     Writeln('New size of ',paramstr(2),' is ',recsize+2,'.');
  144.     Writeln;Writeln;delay(2000);
  145.     clrscr;
  146.     PercentLine(2,0,0);
  147.     OutCount:=0;
  148.     blockread(InFile,InBuffer[3],1);    { Get the header }
  149.     with Header do
  150.     begin
  151.        FirstFree := -1;            { Set deleted record chain }
  152.        NumberFree := 0;            { Number of free records to zero }
  153.        Int1 := 0;                  { Clear index root page }
  154.        RecLen := RecSize + 2;      { Set new record length }
  155.     end;
  156.     blockWrite(OutFile,Header,1);
  157.     for RecNum := 1 to filesize(InFile)-1 do
  158.     begin
  159.        PercentLine(2,RecNum,filesize(InFile)-1);
  160.        seek(InFile,RecNum);
  161.        Inbuffer[1]:=0;
  162.        blockread(InFile,InBuffer[3],1);  { Get a data record }
  163.        if (InBuffer[3] = 0) and (inbuffer[4] = 0) then { Check if deleted }
  164.        begin
  165.           InBuffer[1]:= 0;inbuffer[2]:=0;
  166.           blockWrite(OutFile,InBuffer[1],1); { Write extended new record }
  167.           inc(OutCount);
  168.        end
  169.     end;
  170.     Writeln;Writeln;Writeln;
  171.     Writeln(filesize(InFile)-1,' records read, ',outcount,' records written.');
  172.     close(InFile);close(OutFile);
  173. end.
  174.